//
//  BKGDAddPriceBuyViewController.m
//  bestkeep
//
//  Created by ForgetFairy on 2017/5/8.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKGDAddPriceBuyViewController.h"
#import "BKAddPriceBuyCell.h"
@interface BKGDAddPriceBuyViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) BOOL isFirst;
@property (nonatomic, assign) NSInteger index;

@end

@implementation BKGDAddPriceBuyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initComponents];
}

-(void)initComponents {

    self.title = @"选择加价购商品";
    _isFirst = NO;
    _index = -1;
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
//    [self.tableView registerClass:[BKAddPriceBuyCell class] forCellReuseIdentifier:identifier];
    [self.view addSubview:_tableView];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   
//    BKAddPriceBuyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BKAddPriceBuyCell"];
    BKAddPriceBuyCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[BKAddPriceBuyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BKAddPriceBuyCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_isFirst && self.index == indexPath.row) {
    
        [cell goodsSelected:YES];
    }else{
        [cell goodsSelected:NO];
    }
    
    [cell.imageView1 load:self.goodsCoverImg placeholderImage:[UIImage imageNamed:@"BKGDDefaultBig"]];
    

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 130;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    self.isFirst = NO;
    [self.tableView reloadData];
    
    self.isFirst = YES;
    self.index = indexPath.row;
    [self.tableView reloadData];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
